﻿using Newtonsoft.Json;
using System.ComponentModel;
using System.Windows;
using VisionDesigner.ImageMorph;
using VM.Common.Enums;
using VM.Common.Helper;

namespace Plugin.Morphology
{
    [JsonObject(MemberSerialization.OptOut)]
    public class ParamModel : NotifyPropertyBase
    {
        [Newtonsoft.Json.JsonIgnore]
        public Dictionary<string, string> ParamMap = new Dictionary<string, string>
        {

            { "膨胀", "Dilate" },
            { "腐蚀", "Erode" },
            { "开运算", "Open" },
            { "闭运算", "Close" },
             { "矩形", "Rect" },
              { "十字", "Ellipse" },
               { "椭圆", "Cross" },
                   { "迭代次数", "Iterations" },


        };



        // 形态学数组
        private List<string> _MorArray = EnumHelper.GetEnumDescriptions<MorTypes>();
        [Newtonsoft.Json.JsonIgnore]
        public List<string> MorArray
        {
            get { return _MorArray; }
            set { Set(ref _MorArray, value); }
        }
        //形状数组
        private List<string> _ShapeArray = EnumHelper.GetEnumDescriptions<Shape>();
        [Newtonsoft.Json.JsonIgnore]
        public List<string> ShapeArray
        {
            get { return _ShapeArray; }
            set { Set(ref _ShapeArray, value); }
        }
        //参数

        private int _Iteration = 1;
        public int Iteration
        {
            get { return _Iteration; }
            set
            {
                Set(ref _Iteration, value);
            }
        }

        private int _KernelSizeX = 3;
        public int KernelSizeX
        {
            get { return _KernelSizeX; }
            set
            {
                Set(ref _KernelSizeX, value);
            }
        }
        private int _KernelSizeY = 3;
        public int KernelSizeY
        {
            get { return _KernelSizeY; }
            set
            {
                Set(ref _KernelSizeY, value);

            }

        }
        //类型选择
        public string _MorType = EnumHelper.GetEnumDescription(MorTypes.Dilate);
        [Newtonsoft.Json.JsonIgnore]
        public string MorType
        {
            get { return _MorType; }
            set
            {
                Set(ref _MorType, value);
                UpdateThresholdVisible();
            }
        }

        public string _ShapeType = EnumHelper.GetEnumDescription(Shape.Rect);
        [Newtonsoft.Json.JsonIgnore]
        public string ShapeType
        {
            get { return _ShapeType; }
            set
            {
                Set(ref _ShapeType, value);

            }
        }
        private Visibility _Diedaicishu = Visibility.Visible;
        public Visibility Diedaicishu
        {
            get { return _Diedaicishu; }
            set { Set(ref _Diedaicishu, value); }
        }

        private Visibility _LowThresholdVisible = Visibility.Visible;
        public Visibility LowThresholdVisible
        {
            get { return _LowThresholdVisible; }
            set { Set(ref _LowThresholdVisible, value); }
        }

        private Visibility _HightThresholdVisible = Visibility.Visible;
        public Visibility HightThresholdVisible
        {
            get { return _HightThresholdVisible; }
            set { Set(ref _HightThresholdVisible, value); }
        }



        private Dictionary<string, object> _paramEnum = new Dictionary<string, object>();
        [Newtonsoft.Json.JsonIgnore]
        public Dictionary<string, object> ParamEnum
        {
            get { return _paramEnum; }
            set { Set(ref _paramEnum, value); }
        }



        // 整型
        private Dictionary<string, int> _paramInt = new Dictionary<string, int>();
        [Newtonsoft.Json.JsonIgnore]
        public Dictionary<string, int> ParamInt
        {
            get { return _paramInt; }
            set
            {
                Set(ref _paramInt, value);

            }

        }



        //二值化
        public void Morupdata(CImageMorphTool cImageMor)
        {//形态学方式
            cImageMor.SetRunParam("Type", ParamMap[MorType]);
            //形状
            cImageMor.SetRunParam("Shape", ParamMap[ShapeType]);
            cImageMor.SetRunParam("Iterations", Iteration.ToString());
            cImageMor.SetRunParam("KernelSize_X", KernelSizeX.ToString());
            cImageMor.SetRunParam("KernelSize_Y", KernelSizeY.ToString());


        }



        private void UpdateThresholdVisible()
        {
            switch (MorType)
            {
                case "膨胀":
                    LowThresholdVisible = Visibility.Visible;
                    HightThresholdVisible = Visibility.Visible;
                    Diedaicishu = Visibility.Visible;
                    break;
                case "腐蚀":
                    LowThresholdVisible = Visibility.Visible;
                    HightThresholdVisible = Visibility.Visible;
                    Diedaicishu = Visibility.Visible;
                    break;
                case "开运算":
                    LowThresholdVisible = Visibility.Visible;
                    HightThresholdVisible = Visibility.Visible;
                    Diedaicishu = Visibility.Collapsed;

                    break;
                case "闭运算":
                    LowThresholdVisible = Visibility.Visible;
                    HightThresholdVisible = Visibility.Visible;
                    Diedaicishu = Visibility.Collapsed;
                    break;

                default:
                    break;
            }
        }


    }


    /// <summary>
    /// 输出图像
    /// </summary>

    public enum OutImageTypes
    {
        原图,
        形态学图像,

    }

    /// <summary>
    /// 腐蚀方式
    /// </summary>

    public enum MorTypes
    {
        [Description("膨胀")]
        Dilate,

        [Description("腐蚀")]
        Erode,

        [Description("开运算")]
        Open,

        [Description("闭运算")]
        Close,

    }

    public enum Shape
    {
        [Description("矩形")]
        Rect,

        [Description("十字")]
        Ellipse,

        [Description("椭圆")]
        Cross,


    }





}
